package com.ruoyi.web.cp.service.http;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.web.core.config.ConfigLoader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xiesm
 * @Description:
 * @date 2025-08-21 16:57
 */
@Service
public class CpAo5HttpService {
    @Autowired
    private ConfigLoader configLoader;

    /**
     * @Description: 获取leyu请求头
     * @Author: xiesm
     * @Date: 2025/3/21
     */
    public JSONObject getLeyuHeaders() {
        List<String> cookie = FileUtil.readLines(configLoader.getGamenamesPath() + "leyu-cookie.txt", "utf8");
        JSONObject header = new JSONObject();
        header.put("Cookie", cookie.get(0));
        return header;
    }

    public synchronized JSONObject getList(String date) {
        return HttpUtils.httpJson(ConfigLoader.getConfig().getKjwHost() + "CQShiCai/getBaseCQShiCaiList.do?lotCode=10010&date=" + date,
                "get", null, null);
    }

    public synchronized JSONObject getListFromHwy(String date) {
        return HttpUtils.httpJsonOfHwyAo5(ConfigLoader.getConfig().getKjwHost() + "CQShiCai/getBaseCQShiCaiList.do?lotCode=10010&date=" + date,
                "get", null, null);
    }

    public synchronized JSONArray getListFromOb() {
        return HttpUtils.httpArray(ConfigLoader.getConfig().getLeyuHost() + "member/dayResult?lottery=AULUCKY5&_=1757309725066",
                "get", null, getLeyuHeaders());
    }
}
